const CryptoJS = require('crypto-js') // 引用AES源码js

/**
 * 加密
 * @param encryptString 要加密的字符串
 * @param security 秘钥
 * @returns {string} 加密后的字符串
 */
export function encrypt(encryptString, security) {
  const key = CryptoJS.enc.Utf8.parse('HNKJZYXY' + security)
  var srcs = CryptoJS.enc.Utf8.parse(encryptString);
  var encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

/**
 * 解密
 * @param decryptString 要解密的字符串
 * @returns {string} 解密后的字符串
 */
export function decrypt(decryptString, security) {
  const key = CryptoJS.enc.Utf8.parse('HNKJZYXY' + security);
  var data = CryptoJS.AES.decrypt(decryptString, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(data).toString();
}
